﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Configuration;

namespace WebProyectoSIETE
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection conexion = null;
            try
            {
                conexion = new SqlConnection(ConfigurationManager.ConnectionStrings["cadenaConexion"].ConnectionString);

                conexion.Open();
                SqlCommand comando = new SqlCommand("SELECT TOP(6) [nombreMision], [idMision], [mapaMision], [inicioMision], [descripcionMision], [puntosMision], [dificultadMision], [objetivoMision], [imagenMapa] FROM [Mision],[Mapa] WHERE [mapaMision] = [idMapa] ORDER BY [idMision] DESC", conexion);
                SqlDataReader dr = comando.ExecuteReader();
                Button bt;
                Image img;


                PlaceHolder1.Controls.Add(new LiteralControl("<div class=\"Mision\">"));
                while (dr.Read())
                {
                    PlaceHolder1.Controls.Add(new LiteralControl("<div class=\"objetoTaberna\"> <div class=\"datosObjetoTaberna\"> <div class=\"tipoObjetoTaberna\">" + dr[0].ToString()));
                    PlaceHolder1.Controls.Add(new LiteralControl("</div><div class=\"nombreObjetoTaberna\"> Dificultad: " + dr[6].ToString() + "</div><div class=\"detallesObjetoTaberna\">"));
                    PlaceHolder1.Controls.Add(new LiteralControl("Puntos: " + dr[5].ToString() + "<br //> Descripcion: " + dr[4].ToString() + "<br //> <div class=\"imagenObjetoTaberna\">"));

                    img = new Image();
                    bt = new Button();

                    img.ImageUrl = "~/img/" + dr[8];
                    img.ID = "img" + dr[0].ToString();
                    img.Height = 150;
                    img.Width = 150;
                    img.AlternateText = dr[2].ToString();
                    PlaceHolder1.Controls.Add(img);
                    PlaceHolder1.Controls.Add(new LiteralControl("</div>"));
                    PlaceHolder1.Controls.Add(new LiteralControl("</div>"));
                    PlaceHolder1.Controls.Add(new LiteralControl("</div>"));
                    PlaceHolder1.Controls.Add(new LiteralControl("</div>"));

                }
                PlaceHolder1.Controls.Add(new LiteralControl("</div>"));
            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {

                conexion.Close();
            }
        }
    }
}